const mongoose = require('mongoose');

const accessoryRequestSchema = new mongoose.Schema({
  machineId: { type: mongoose.Schema.Types.ObjectId, ref: 'Machine', required: true },
  status: {
    type: String,
    required: true,
    enum: ['待申请', '已申请'],
    default: '待申请'
  },
  requestNumber: {
    type: String,
    default: ''
  },
  createdAt: {
    type: Date,
    default: Date.now
  },
  updatedAt: {
    type: Date,
    default: Date.now
  }
});


accessoryRequestSchema.pre('save', function (next) {
  this.updatedAt = Date.now();
  next();
});

const AccessoryRequest = mongoose.model('AccessoryRequest', accessoryRequestSchema);

module.exports = AccessoryRequest;